import {Router,Route ,Switch ,Redirect} from 'react-router-dom'
// BrowserRouter = Router + BrowserHistory
import Layout from '@/pages/Layout/Layout.jsx'
import Login from '@/pages/Login/Login.jsx'
import NotFound from '@/pages/NotFound/NotFound.jsx'
import '@/App.scss'

import history from '@/utils/history'
import PrivateRoute from './components/PrivateRoute'

function App() {
  return (
    <div className="app">
      <Router history={history}>
      <Switch>
        {/* 1.0版本 */}
        {/* <Route path='/Layout' render={()=>{
         if(hasToken()){
           return <Layout />
         } else{
           return <Redirect to='/login' />
         }
        }} /> */}
        <Route path='/login' component={Login} />
        {/* 2.0封装版 */}
        <PrivateRoute path="/Layout" component={Layout} />
        {/* 重定向到 Layout */}
        <Redirect from='/' to='/Layout' />
        <Route path='/NotFound' component={NotFound} />
        {/* 重定向到 NotFound */}
        <Redirect from='/' to='/NotFound' />
      </Switch>
      </Router>
    </div>
  );
}

export default App;
